package com.yunkeji.common.msg;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.yunkeji.common.constant.SysIdConstant;
import com.yunkeji.common.enums.app.MsgTypeEnums;
import com.yunkeji.common.msg.bo.PrivateMsg;
import com.yunkeji.common.msg.bo.RollingMsg;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public class PushMessage {

    @AllArgsConstructor
    @Getter
    public enum SysMsgType {
        广场信息(1),
        通知信息(2),
        礼物信息(3),
        评分信息(4),
        私聊消息(5),
        客服消息(6);
        private Integer msgType;
    }

    /**
     * 刷新Kmsg的Token
     *
     * @return
     */
    public static String refreshKmsgToken(Long platformId) {
        return Push.refreshKmsgToken(platformId);
    }

    /** 发送短信 */
    public static void sendSMSCode(String phoneNum, String code, String plat) {
        Push.sendSMSCode(phoneNum, code, plat);
    }

    /** 踢下线 */
    public static void kickout(Long platformId, String reason) {
        Push.kickout(platformId, reason);
    }

    /**
     * 发送跑马灯
     *
     * @param to
     */
    public static boolean sendRollingMsg(List<Long> to, RollingMsg rollingMsg) {
        return Push.sendRollingMsg(to, rollingMsg);
    }

    /**
     * 发送链接消息
     *
     * @param to
     */
    public static boolean sendLinkMsg(List<Long> to, String content, String url) {
        return Push.sendLinkMsg(to, content, "aidong://" + url);
    }

    /**
     * 发送收条消息
     *
     * @param to
     */
    public static boolean sendReceipt(Long from, Long to, JSONObject param) {
        return Push.sendReceiptBatch(from, ListUtil.of(to), param);
    }

    /**
     * 发送单条普通文本消息-个人-私聊信息
     *
     * @param to
     */
    public static boolean sendTextSinglePrivate(Long from, Long to, PrivateMsg privateMsg) {
        return Push.sendTextBatch(
                from,
                ListUtil.of(to),
                JSONUtil.parseObj(privateMsg).set("type", SysMsgType.私聊消息.getMsgType()));
    }
    /**
     * 发送单条普通文本消息-个人-私聊信息
     *
     * @param to
     */
    public static boolean sendTextBatchPrivate(Long from, List<Long> to, PrivateMsg privateMsg) {
        return Push.sendTextBatch(
                from, to, JSONUtil.parseObj(privateMsg).set("type", SysMsgType.私聊消息.getMsgType()));
    }
    /**
     * 发送单条普通文本消息-个人-私聊信息
     *
     * @param to
     */
    public static boolean sendTextSingle(Long from, Long to, String content) {
        return Push.sendTextSingle(
            from, to, content);
    }
    /**
     * 发送单条普通文本消息-系统-广场信息
     *
     * @param to
     */
    public static boolean sendTextSingleSysSquare(Long to, PrivateMsg content) {
        JSONObject type = JSONUtil.parseObj(content).set("type", SysMsgType.广场信息.getMsgType());
        return Push.sendTextBatch(SysIdConstant.系统, ListUtil.of(to), type);
    }

    /**
     * 发送单条普通文本消息-系统-评分
     *
     * @param to
     */
    public static boolean sendTextSingleSysScore(Long to, String content) {
        return Push.sendTextBatch(
                SysIdConstant.系统,
                ListUtil.of(to),
                JSONUtil.createObj()
                        .set("type", SysMsgType.评分信息.getMsgType())
                        .set("content", content));
    }

    /**
     * 发送单条普通文本消息-系统-礼物
     *
     * @param to
     */
    public static boolean sendTextSingleSysGift(Long to, PrivateMsg content) {
        JSONObject type = JSONUtil.parseObj(content).set("type", SysMsgType.礼物信息.getMsgType());
        return Push.sendTextBatch(SysIdConstant.系统, ListUtil.of(to), type);
    }

    /**
     * 发送单条普通文本消息-系统-通知信息
     *
     * @param to
     */
    public static boolean sendSysNotify(Long to, String content) {
        return sendSysNotifyBatch(ListUtil.of(to), content);
    }

    /**
     * 发送多条普通文本消息-系统-通知信息
     *
     * @param to
     */
    public static boolean sendSysNotifyBatch(List<Long> to, String content) {
        return Push.sendTextBatch(
            SysIdConstant.系统,
            to,
            JSONUtil.createObj()
                .set("type", SysMsgType.通知信息.getMsgType())
                .set("content", content));
    }
    /**
     * 客服给用户发消息
     *
     * @param to
     */
    public static boolean serviceToUser(Long from, Long to, String content) {
        return Push.serviceToUser(
                from,
                to,
                JSONUtil.createObj()
                        .set("type", SysMsgType.客服消息.getMsgType())
                        .set("content", content));
    }

    /** 用户发消息给客服 */
    public static boolean userToService(Long from, PrivateMsg content) {
        JSONObject type = JSONUtil.parseObj(content).set("type", SysMsgType.私聊消息.getMsgType());
        return Push.userToService(from, type);
    }
    /**
     * 发送单条普通文本消息-运营
     *
     * @param to
     */
    public static boolean sendOper(Long to, String content) {
        return Push.sendTextBatch(
                SysIdConstant.运营, ListUtil.of(to), JSONUtil.createObj().set("content", content));
    }
    /**
     * 推送通话信令-单个
     *
     * @param from
     * @param to
     */
    public static boolean pushCallSignalSingle(
            Long from, Long to, JSONObject content, MsgTypeEnums msgTypeEnums) {
        return Push.pushCallSignalBatch(from, ListUtil.of(to), content, msgTypeEnums);
    }
    /**
     * 推送通话信令
     *
     * @param from
     * @param to
     */
    public static boolean pushCallSignalBatch(
            Long from, List<Long> to, JSONObject content, MsgTypeEnums msgTypeEnums) {
        return Push.pushCallSignalBatch(from, to, content, msgTypeEnums);
    }
}
